2020-2021 Sunseeker Telemetry and Lighting System
rtc_b_ex1_calendermodeLPM0.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
64 //******************************************************************************
65 #include "driverlib.h"
66 
67 volatile Calendar newTime;
68 
69 void main (void)
70 {
71  Calendar currentTime;
72 
73  WDT_A_hold(WDT_A_BASE);
74 
75  //Set P1.0 to output direction
76  GPIO_setAsOutputPin(
77  GPIO_PORT_P1,
78  GPIO_PIN0
79  );
80 
81  //Initialize LFXT1
82  UCS_turnOnLFXT1(UCS_XT1_DRIVE_3,
83  UCS_XCAP_3
84  );
85 
86  //Setup Current Time for Calendar
87  currentTime.Seconds = 0x00;
88  currentTime.Minutes = 0x26;
89  currentTime.Hours = 0x13;
90  currentTime.DayOfWeek = 0x03;
91  currentTime.DayOfMonth = 0x20;
92  currentTime.Month = 0x07;
93  currentTime.Year = 0x2011;
94 
95  //Initialize Calendar Mode of RTC
96  /*
97  * Base Address of the RTC_B
98  * Pass in current time, intialized above
99  * Use BCD as Calendar Register Format
100  */
101  RTC_B_initCalendar(RTC_B_BASE,
102  &currentTime,
103  RTC_B_FORMAT_BCD);
104 
105  //Setup Calendar Alarm for 5:00pm on the 5th day of the week.
106  //Note: Does not specify day of the week.
107  RTC_B_configureCalendarAlarmParam param = {0};
108  param.minutesAlarm = 0x00;
109  param.hoursAlarm = 0x17;
110  param.dayOfWeekAlarm = RTC_B_ALARMCONDITION_OFF;
111  param.dayOfMonthAlarm = 0x05;
112  RTC_B_configureCalendarAlarm(RTC_B_BASE, &param);
113 
114  //Specify an interrupt to assert every minute
115  RTC_B_setCalendarEvent(RTC_B_BASE,
116  RTC_B_CALENDAREVENT_MINUTECHANGE);
117 
118  //Enable interrupt for RTC Ready Status, which asserts when the RTC
119  //Calendar registers are ready to read.
120  //Also, enable interrupts for the Calendar alarm and Calendar event.
121  RTC_B_clearInterrupt(RTC_B_BASE,
122  RTCRDYIFG + RTCTEVIFG + RTCAIFG);
123  RTC_B_enableInterrupt(RTC_B_BASE,
124  RTCRDYIE + RTCTEVIE + RTCAIE);
125 
126  //Start RTC Clock
127  RTC_B_startClock(RTC_B_BASE);
128 
129  //Enter LPM0 mode with interrupts enabled
130  __bis_SR_register(LPM0_bits + GIE);
131  __no_operation();
132 }
133 
134 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
135 #pragma vector=RTC_VECTOR
136 __interrupt
137 #elif defined(__GNUC__)
138 __attribute__((interrupt(RTC_VECTOR)))
139 #endif
140 void RTC_B_ISR (void)
141 {
142  switch (__even_in_range(RTCIV,16)){
143  case 0: break; //No interrupts
144  case 2: //RTCRDYIFG
145  //Toggle P1.0 every second
146  GPIO_toggleOutputOnPin(
147  GPIO_PORT_P1,
148  GPIO_PIN0);
149  break;
150  case 4: //RTCEVIFG
151  //Interrupts every minute
152  __no_operation();
153 
154  //Read out New Time a Minute Later BREAKPOINT HERE
155  newTime = RTC_B_getCalendarTime(RTC_B_BASE);
156  break;
157  case 6: //RTCAIFG
158  //Interrupts 5:00pm on 5th day of week
159  __no_operation();
160  break;
161  case 8: break; //RT0PSIFG
162  case 10: break; //RT1PSIFG
163  case 12: break; //Reserved
164  case 14: break; //Reserved
165  case 16: break; //Reserved
166  default: break;
167  }
168 }
169 
MPU_initThreeSegmentsParam param
__no_operation()
void main(void)
void RTC_B_ISR(void)
volatile Calendar newTime